
<template>
  <div class="main">
    <el-menu
      :default-active="getactiveRoute"
      mode="horizontal"
      class="bar"
      @select="handleSelect"
      background-color="transparent"
      text-color="#fff"
      router
      active-text-color="#fff"
    >
      <el-menu-item v-for="(item,index) in getOneMenu" :key="index" :index="item.path">{{item.menuTitle}}</el-menu-item>
      <!-- <el-menu-item index="/xiaoshou">销售</el-menu-item>
      <el-menu-item index="/inventory">库存</el-menu-item> -->
      <!-- <el-menu-item index="4">资金</el-menu-item> -->
      <!-- <el-menu-item index="/Xingwei">行为</el-menu-item> -->
      <!-- <el-menu-item index="6">报表</el-menu-item> -->
      <!-- <el-menu-item index="/system">系统</el-menu-item> -->
    </el-menu>
  </div>
</template>

<script>
import { mapMutations,mapGetters } from "vuex";
export default {
  data() {
    return {
      activeRoute: JSON.parse(sessionStorage.currRoute||"[]")[0]?.path || "/purchase",
    };
  },
  created() {},
  mounted() {
    console.log(this.$router.options.routes)
    let arr = JSON.parse(sessionStorage.currRoute ||"null")||this.$router.options.routes.filter((v) => v.path === "/purchase");
    this["menuRoutes/setRoutes"](arr);
  },
  methods: {
    ...mapMutations(["menuRoutes/setRoutes"]),
    handleSelect(path) {
      console.log(111)
      this["menuRoutes/setRoutes"](
        this.$router.options.routes.filter((v) => v.path === path)
      );
    },
  },
  computed:{
    ...mapGetters("menuRoutes",["getRoutes"]),
    getactiveRoute(){
      // this.activeRoute=this["getRoutes"][0]?.path
      return this["getRoutes"][0]?.path
    }
    ,
    getOneMenu(){
      let router=JSON.parse(localStorage.addRoute)
      return router.map(v=>{
        return {
          path:v.path,
          menuTitle:v.meta.menuTitle
        }
      })
    }
  }
};
</script>

<style lang="scss" scoped>
.main .bar ::v-deep li {
  height: 50px;
  line-height: 50px;
}
</style>